package com.spark.util;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.spark.dao.SessionFactory;

@SuppressWarnings("unchecked")
public class InitializerHelper {
	
	private static final String KEY_ACCOUNTS = "GLD_ACCOUNTS_";
	
	
	public static void initAccount(Integer accountSetId){
		List accountsList = retrievalAccounts(accountSetId);
		if(accountsList == null) {
			SqlSession sqlSession = SessionFactory.getSession();
			try {
				List list = (List) sqlSession.selectList("init_accounts.selectAllAccounts",accountSetId);
				MemcachedHelper.set(KEY_ACCOUNTS.concat(accountSetId.toString()),0,list);
			} finally {
				SessionFactory.closeSession(sqlSession);
			}
		}
	}
	
	
	public static List retrievalAccounts(Integer accountSetId){
		return (List)MemcachedHelper.get(KEY_ACCOUNTS.concat(accountSetId.toString()));
	}
}
